package com.controller;

import com.dto.GoodsDTO;
import com.dto.UnloadGoodsDTO;
import com.entity.*;
import com.service.GoodsEntityService;
import com.service.GoodsService;
import com.service.GoodsSortService;
import com.service.UnloadGoodsService;
import com.util.CurrentUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/goods")
public class GoodsController {
    @Autowired
    private UnloadGoodsService unloadGoodsService ;
    @Autowired
    private CurrentUser currentUser;
    @Autowired
    private GoodsService goodsService;
    @Autowired
    private GoodsSortService goodsSortService;
    @Autowired
    private GoodsEntityService goodsEntityService;
    @RequestMapping("/findEntity")
    public Result findEntity(){
        List<GoodsEntity> goodsEntityList = goodsService.findAll();
        return  new Result<>(200,"查询成功",goodsEntityList);
    }

    @RequestMapping("/getByGid")
    private Result getByGid(Integer gid){
        System.out.println(gid);
        return Result.ok(goodsService.getByGid(gid));
    }
    @RequestMapping("/findgoods")
    public Result findGoods(){
        List<GoodsDTO> list = goodsService.findGoodsDTO();
        return new Result<>(200,"查询成功",list);
    }
    @RequestMapping("/findGoodsSort")
    public Result findGoodsSort(){
        log.info("查找类");
        List<GoodsSort> goodsSorts = goodsSortService.findTree();
        return new Result(200,"查找成功",goodsSorts);
    }
    @RequestMapping("/add")
    public Result add(@RequestBody GoodsEntity goodsEntity){
        System.out.println(goodsEntity);
//        log.info("新增产品",goodsEntity);
        goodsEntityService.add(goodsEntity);
        return new Result<>(200,"添加成功",null);
    }
}
